<?php
/**
 * Created by PhpStorm.
 * User: Ason
 * Date: 15-6-12
 * Time: 下午4:29
 *
 * 系统设置
 */

class Setting extends Admin_controller {

	public function __construct(){
		parent::__construct();
		parent::logged_check();
	}

	/**
	 * 基本设置
	 */
	public function index(){

		$this->load->model( 'site_model' );
		$this->data[ 'siteinfo' ] = $this->site_model->get_site_info();

		$this->view( 'setting/site', $this->data );
	}
	
	/* 保存网站配置信息
	 * 前台通过ajax-post提交
	 */
	public function save_site(){
		
		$json = [ 'status'=>'error', 'error'=>'未知错误' ];
		
		$post = $this->input->post( null, true );
		
		if( empty( $post['name'] ) ){
			$json[ 'error' ] = '系统名称不能为空';
			die( json_encode( $json ) );
		}
		if(	$this->db->replace( 'site', $post ) ){
			$json[ 'status' ] = 'success';
			$json[ 'error' ] = '保存成功';
		}
			
		die( json_encode( $json ) );
		
	}

	/**
	 * 数据库管理
	 * */
	public function db(){

		//获取所有表
		$this->data[ 'tables' ] = $this->db->list_tables();

		$this->view( 'setting/db', $this->data );
	}
}